package org.softmed.action.builder;

import org.softmed.action.Action;
import org.softmed.action.converter.ActionDescriptionXMLConverter;
import org.softmed.action.description.ActionDescription;
import org.softmed.action.resolver.ActionResolver;
import org.softmed.action.workarea.WorkArea;

import com.google.inject.Inject;

public class DefaultActionCreator implements ActionCreator {

	@Inject
	ActionResolver actionResolver;

	@Inject
	ActionDescriptionXMLConverter actionDescriptionXMLConverter;

	@Override
	public Action getActionFromDescription(ActionDescription description)
			throws Throwable {
		Action action = actionResolver.instantiate(description);
		action.setWorkArea(new WorkArea());
		return action;
	}

	@Override
	public Action getActionFromXML(String xml) throws Throwable {
		ActionDescription ad = actionDescriptionXMLConverter
				.convertToActionDescription(xml);
		return getActionFromDescription(ad);
	}

	public ActionDescriptionXMLConverter getActionDescriptionXMLConverter() {
		return actionDescriptionXMLConverter;
	}

	public void setActionDescriptionXMLConverter(
			ActionDescriptionXMLConverter actionDescriptionXMLConverter) {
		this.actionDescriptionXMLConverter = actionDescriptionXMLConverter;
	}

	public ActionResolver getActionResolver() {
		return actionResolver;
	}

	public void setActionResolver(ActionResolver actionResolver) {
		this.actionResolver = actionResolver;
	}

}
